<template>
  
</template>

<script>
import { URLP, UseCodeToToken } from './../../libs/api_v1'
import { search } from './../../libs/api'

const jwt_token = () => {
  return Cookies.get("authtoken")
}
const time_now = () => {
  return parseInt(new Date().getTime()/1000)
}
export default {
    data:()=>({

    }),
    name: "Oauth",
    created:function(){
      var oauth = URLP("oauth")
      var code = URLP("code")
      if(oauth == "wechat"){
        UseCodeToToken(code)
        .then((resp)=>{
            var res = resp.data
            if (res.code == 1){
                this.$cookies.set('authtoken', res.data, { expires: 365 })
                if( search('bind') == 'yes'){
                  window.location.href = '/auth/bind'
                  return
                }
                if(search("redirect_call")){
                  window.location.href = decodeURIComponent(search("redirect_call"))
                }else{
                  window.location.href = '/'
                }
                return
            }else{
              window.location.href = '/auth/login'
            }
        })
        .catch((err)=>{
            window.location.href = '/auth/login'
        })
      }
    }
    
}
</script>

<style>

</style>